<?php
/**
 * Create By: PhpStorm
 * User: yihua
 * File: GetuserAddress.php
 * Date: 2017/1/6
 * Time: 0:00
 */
namespace app\api\model\page\user;

use       app\api\model\dao\UserAddress;
use app\library\Error;
use app\library\PageBase;

class GetUserAddress extends PageBase
{
    private $objUserAddressModel;

    public function __construct()
    {
        parent::__construct();
        $this->objUserAddressModel = new UserAddress();
    }

    public function excute($param)
    {
        $ret = $this->checkToken($param);
        if (false === $ret) {
            //return $this->getRes(Error::ERR_NO_AUTH);
        }

        if (!isset($param['user_id'])) {
            return $this->getRes(Error::ERR_PARAM);
        }
        $resModel = $this->objUserAddressModel->getAddressByUserid($param['user_id']);
        if (false === $resModel) {
            return $this->getRes(Error::ERR_SYS);
        } else {
            //home后台管理使用时，使用修改器修饰后的数据
            //var_dump($param);
            //var_dump(isset($param['home']));
            if (isset($param['home']) && (true == $param['home'])) {
                $this->data = $resModel;
            } else {
                //api调用时，获取原始数据
                $this->data = $this->modelToArray($resModel);
            }
            return $this->getRes();
        }
    }
}


